import os
import shutil 
import time
import string

NukeFile = r"\\skye\cask2\show\bedtime\wt\wt010\nuke\wt010_DA_mh_V094_Rosk1a.nk"
FromDirPos = r"//skye/cask2/show"
osFromDirPos = os.path.realpath(FromDirPos)
print osFromDirPos
LocalDir = "e:\\sam"



def prepLocalPaths(osRef):
    
    LocalFileDir = string.replace(os.path.dirname(osRef),osFromDirPos,LocalDir)
    print "building local folder "+ LocalFileDir
    try:
        os.makedirs(LocalFileDir)
        print "done"
       
    except:
        print "failed to build "+ LocalFileDir 
        
    localCopy (LocalFileDir)
        
def testForCopy(osRef):
    print "testing if files need to  be copied"
    
    
def localCopy (LocalFileDir):
    currentDir = os.path.dirname(LocalFileDir)
    for file in os.listdir(currentDir):
        currentFile = os.path.join(currentDir,file)
        if os.path.isfile(currentFile):
            print "nothing"
            #shutil.copy2(currentFile, LocalFileDir)
            #print currentFile


with open(NukeFile) as f:
    prepLocalPaths(NukeFile)
    for line in f:
        if "file" in line:
            posixRef = line[6:]
            print posixRef
            osRef = os.path.realpath(line[6:])
            print osRef 
            if os.path.exists(os.path.dirname(osRef)):
                print osRef +" dir exists"
                prepLocalPaths(osRef)
                #testForCopy (osRef)
                
            else:
                print osRef +"doesnt exist"





    

    
#os.makedirs(ToDir)
#shutil.copy2(FromFile,ToDir)
#oldStat = os.stat("e:\sam\ponies\cabTowardFG1Stretch.2.0001.tif")

# last modified time (actual age of file)
#print oldStat.st_mtime
#print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(oldStat.st_mtime))